package com.zlzxm.shoesmarket.view.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.adapter.ADMatchUser;
import com.zlzxm.shoesmarket.view.adapter.ADSizePeopleNum;
import com.zlzxm.shoesmarket.viewmodel.VMGoodsRequestNote;

/**
 * CREATE BY zlzxm ON 4/22/21
 */
public class FMGoodsRequestNote extends BaseFragment implements View.OnClickListener{

    public static FMGoodsRequestNote newInstance() {

        Bundle args = new Bundle();

        FMGoodsRequestNote fragment = new FMGoodsRequestNote();
        fragment.setArguments(args);
        return fragment;
    }

    private FMGoodsRequestNote() {
    }

    private RecyclerView rvSize,rvUser;

    private VMGoodsRequestNote vmGoodsRequestNote;

    private final ADSizePeopleNum adSizePeopleNum = new ADSizePeopleNum();

    private final ADMatchUser adMatchUser = new ADMatchUser();

    private LinearLayout llNormal,llTwo,llThree,llDiy;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fm_goods_request_note,container,false);
    }

    @Override
    protected void initView(@NonNull View view, @NonNull Bundle savedInstanceState) {
        super.initView(view, savedInstanceState);
        rvSize = ZViewHelp.findById(view,R.id.rvSize);
        rvSize.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.HORIZONTAL,false));
        rvSize.setAdapter(adSizePeopleNum);

        rvUser = ZViewHelp.findById(view,R.id.rvUser);
        rvUser.setLayoutManager(new LinearLayoutManager(getContext()));
        rvUser.setAdapter(adMatchUser);

        llNormal = ZViewHelp.setOnClickListener(view,R.id.llNormal,this);
        llTwo = ZViewHelp.setOnClickListener(view,R.id.llTwo,this);
        llThree = ZViewHelp.setOnClickListener(view,R.id.llThree,this);
        llDiy = ZViewHelp.setOnClickListener(view,R.id.llDiy,this);

    }

    @Override
    protected void initViewModel() {
        super.initViewModel();
        vmGoodsRequestNote = new ViewModelProvider(this).get(VMGoodsRequestNote.class);
        vmGoodsRequestNote.getLiveSizeData().observe(this,adSizePeopleNum::setList);
        vmGoodsRequestNote.getLiveUser().observe(this,adMatchUser::setList);
    }

    @Override
    protected void initData() {
        super.initData();
        vmGoodsRequestNote.requestSizeData();
        vmGoodsRequestNote.requestSizeDataUser();
    }

    @Override
    public void onClick(View v) {

        int id = v.getId();

        if(id == R.id.llNormal ||id == R.id.llTwo||id == R.id.llThree||
                id == R.id.llDiy){

            changeTag(v);

        }

    }


    private void changeTag(View view){

        llNormal.setSelected(false);
        llTwo.setSelected(false);
        llThree.setSelected(false);
        llDiy.setSelected(false);

        view.setSelected(true);


    }

}
